﻿using System;
using System.Web;

namespace ZHDJ.Core.Util
{
    public class CacheHelper
    {
        /// <summary>
        /// 是否存在缓存
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns></returns>
        public static bool IsExist(string key)
        {
            return HttpContext.Current.Cache[key] != null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="OutTime"></param>
        public static void Add(string key, object value, DateTime OutTime)
        {
            HttpContext.Current.Cache.Insert(key, value, null, OutTime, TimeSpan.Zero);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="OutTime"></param>
        public static void Remove(string key)
        {
            if (IsExist(key))
                HttpContext.Current.Cache.Remove(key);
        }

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetCache(string key)
        {
            if (IsExist(key))
            {
                return HttpContext.Current.Cache[key];
            }
            else
            {
                return null;
            }
        }
    }
}
